package com.sghd.candy.module.box.manager;

import com.sghd.common.ramcache.anno.Inject;
import com.sghd.common.ramcache.service.EntityCacheService;
import com.sghd.pojo.candy.box.enums.KeyType;
import org.springframework.stereotype.Component;

/**
 * @author Allen
 * @date 2018/12/25
 */
@Component
public class PlayerBoxManager {
    @Inject
    private EntityCacheService<Long, PlayerBox> playerBoxCache;

    public PlayerBox getPlayerBox(long playerId) {
        return playerBoxCache.loadOrCreate(playerId, builder -> PlayerBox.valueOf(playerId));
    }

    public void change(PlayerBox playerBox, KeyType keyType, int useCount) {
        playerBox.change(keyType, useCount);
    }
}
